package com.gxa.p2p.controller;

import com.gxa.p2p.common.JsonResult;
import com.gxa.p2p.pojo.Activity;
import com.gxa.p2p.pojo.Activitylog;
import com.gxa.p2p.service.ActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

/**
 * @author R
 * @data 2021-10-26 10:19
 */
@CrossOrigin
@RestController
@RequestMapping("/activity")
@Api("活动控制层")
public class ActivityController {

    @Autowired
    ActivityService service = null;


    /**
     * 饶贵钢
     * @param page 页数
     * @param size 每页记录数
     * @return
     */
    @PostMapping("/findNewActivityByPage")
    @ApiOperation("查询新人活动策略")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页码",required = true,dataType = "int"),
            @ApiImplicitParam(name = "size",value = "每页记录数",required = true,dataType = "int")
    })
    public Map findNewActivityByPage(@RequestParam("page") Integer page,
                                  @RequestParam("size") Integer size){
        List<Activity> newActivityByPage = service.findNewActivityByPage(page, size);
        Integer newActivityCount = service.findNewActivityCount(page, size);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("查询成功");
        jsonResult.setCode("200");
        jsonResult.setData(newActivityByPage);
        jsonResult.put("count",newActivityCount);
        return jsonResult.getDataMap();
    }

    /**
     * 饶贵钢
     * @param activity 修改的活动的详情信息
     * @return 返回是否修改成功
     */
    @PostMapping("/updateNewActivity")
    @ApiOperation("修改新人活动策略")
    @ApiImplicitParam(name = "activity",value = "活动详情",required = true,paramType = "body")
    public Map updateNewActivity(Activity activity){
        System.out.println(activity);
        activity.setUpdateTime(new Timestamp(System.currentTimeMillis()));
        service.updateNewActivity(activity);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("修改成功");
        jsonResult.setCode("200");
        return jsonResult.getDataMap();
    }

    /**
     * 查询签到活动策略
     * 饶贵钢
     * @param page 页码
     * @param size 记录数
     * @return 返回查询结果
     */
    @PostMapping("/findSignActivityByPage")
    @ApiOperation("查询签到活动策略")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页码",required = true,dataType = "int"),
            @ApiImplicitParam(name = "size",value = "每页记录数",required = true,dataType = "int")
    })
    public Map findSignActivityByPage(@RequestParam("page") Integer page,
                                     @RequestParam("size") Integer size){
        List<Activity> signActivityByPage = service.findSignActivityByPage(page, size);
        Integer signActivityCount = service.findSignActivityCount(page, size);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("查询成功");
        jsonResult.setCode("200");
        jsonResult.setData(signActivityByPage);
        jsonResult.put("count",signActivityCount);
        return jsonResult.getDataMap();
    }

    /**
     * rgg
     * 修改签到活动
     * @param activity 活动详情信息
     * @return 返回修改结果
     */
    @PostMapping("/updateSignActivity")
    @ApiOperation("修改签到活动策略")
    @ApiImplicitParam(name = "activity",value = "活动详情",required = true,paramType = "body")
    public Map updateSignActivity(Activity activity){
        System.out.println(activity);
        activity.setUpdateTime(new Timestamp(System.currentTimeMillis()));
        service.updateSignActivity(activity);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("修改成功");
        jsonResult.setCode("200");
        return jsonResult.getDataMap();
    }

    /**
     * 饶贵钢
     * 查询邀请活动策略
     * @param page 页码
     * @param size 记录数
     * @return 返回查询结果
     */
    @PostMapping("/findInviteActivityByPage")
    @ApiOperation("查询邀请活动策略")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页码",required = true,dataType = "int"),
            @ApiImplicitParam(name = "size",value = "每页记录数",required = true,dataType = "int")
    })
    public Map findInviteActivityByPage(@RequestParam("page") Integer page,
                                      @RequestParam("size") Integer size){
        List<Activity> inviteActivityByPage = service.findInviteActivityByPage(page, size);
        Integer inviteActivityCount = service.findInviteActivityCount(page, size);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("查询成功");
        jsonResult.setCode("200");
        jsonResult.setData(inviteActivityByPage);
        jsonResult.put("count",inviteActivityCount);
        return jsonResult.getDataMap();
    }

    /**
     * 修改邀请活动策略
     * @param activity 修改后的活动实体
     * @return 返回修改结果
     */
    @PostMapping("/updateInviteActivity")
    @ApiOperation("修改邀请活动策略")
    @ApiImplicitParam(name = "activity",value = "活动详情",required = true,paramType = "body")
    public Map updateInviteActivity(Activity activity){
        System.out.println(activity);
        activity.setUpdateTime(new Timestamp(System.currentTimeMillis()));
        service.updateInviteActivity(activity);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("修改成功");
        jsonResult.setCode("200");
        return jsonResult.getDataMap();
    }

    /**
     * 饶贵钢
     * @param phone 推荐人手机
     * @param name 被邀请人姓名
     * @param event 奖励事件
     * @param state 发送状态
     * @param from 起止时间
     * @param to 截止时间
     * @param page 页码
     * @param size 每页记录数
     * @return 返回查询结果
     */
    @PostMapping("/findInviteActivityLogByPage")
    @ApiOperation("查询邀请活动发放记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone",value = "推荐人手机",required = false,dataType = "String"),
            @ApiImplicitParam(name = "name",value = "被邀请人姓名",required = false,dataType = "String"),
            @ApiImplicitParam(name = "event",value = "奖励事件",required = false,dataType = "String"),
            @ApiImplicitParam(name = "state",value = "发送状态",required = false,dataType = "Boolean"),
            @ApiImplicitParam(name = "from",value = "起止时间",required = false,dataType = "String"),
            @ApiImplicitParam(name = "to",value = "截止时间",required = false,dataType = "String"),
            @ApiImplicitParam(name = "page",value = "页码",required = true,dataType = "int"),
            @ApiImplicitParam(name = "size",value = "每页记录数",required = true,dataType = "int")
    })
    public Map findActivityLogByPage(@RequestParam("phone") String phone,
                                     @RequestParam("name") String name,
                                     @RequestParam("event") String event,
                                     @RequestParam("state") Boolean state,
                                     @RequestParam("from") String from,
                                     @RequestParam("to") String to,
                                     @RequestParam("page") Integer page,
                                     @RequestParam("size") Integer size){
        List<Activitylog> activityLogByPage = service.findActivityLogByPage(phone, name, event, state, from, to, page, size);
        Integer inviteActivityCount = service.findActivityLogCount(phone, name, event, state, from, to, page, size);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("查询成功");
        jsonResult.setCode("200");
        jsonResult.setData(activityLogByPage);
        jsonResult.put("count",inviteActivityCount);
        return jsonResult.getDataMap();
    }

}
